import 'package:flutter/material.dart';
import 'package:xws/utils/theme_util.dart';
import 'package:xws/widgets/app_btn.dart';

/// 提示对话框
class Tips extends StatelessWidget {
  const Tips({
    required this.content,
    Key? key,
    this.title,
    this.onCheck,
    this.onCancel,
    this.checkText,
    this.cancelText,
  }) : super(key: key);

  final String content;

  final String? title;
  final Function()? onCheck;
  final Function()? onCancel;
  final String? checkText;
  final String? cancelText;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 300,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            const SizedBox(height: 20),
            Text(title ?? '',
                textAlign: TextAlign.center,
                style: const TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                )),
            const SizedBox(height: 20),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: Text(
                content,
                style: const TextStyle(fontSize: 14),
              ),
            ),
            const SizedBox(height: 20),
            _buildBtns(context),
          ],
        ),
        decoration: BoxDecoration(
          color: white(context),
          borderRadius: BorderRadius.circular(10),
        ),
      ),
    );
  }

  Widget _buildBtns(BuildContext context) {
    return SizedBox(
      height: 60,
      child: Row(
        children: <Widget>[
          _btn(context, cancelText ?? '取消', onCancel, false),
          _btn(context, checkText ?? '确认', onCheck, true),
        ],
      ),
    );
  }

  Widget _btn(
    BuildContext context,
    String text,
    Function()? func,
    bool value,
  ) {
    return Flexible(
      child: AppBtn(
        onTap: () {
          func?.call();
          Navigator.pop(context, value);
        },
        alignment: Alignment.center,
        radius: 0,
        text: text,
        textStyle: TextStyle(
          color: value ? theme(context) : red(context),
          fontSize: 16,
        ),
        color: Colors.transparent,
      ),
    );
  }
}
